home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- Project : GUSI - Grand Unified Socket Interface
- File : TFileSpec.h - C and C++ routines to deal with path names
- Author : Matthias Neeracher
- Started : 06Jun92 Language : MPW C/C++
- Modified : 08Sep92 MN Permission flags were the wrong way around
- 12Sep92 MN Renamed
- 15Nov92 MN Forgot a few consts
- 15Nov92 MN Renamed once again
- 15Nov92 MN Made suitable for use from C programs
- 08Dec92 MN Made Default() public
- 03Jan93 MN Prevent multiple includes
- 15Jan93 MN IsParentOf, operator ==
- Last : 15Jan93
- *********************************************************************/
-
- #ifndef _TFILESPEC_
- #define _TFILESPEC_
-
- /* These routines run both under System 7 and under older systems. */
-
- #include <Files.h>
-
- #ifdef __cplusplus
-
- /************************** The C++ only interface ***************************/
-
- class TFileSpec : public FSSpec {
- static OSErr error;
- static short curVol;
- static long curDir;
-
- public:
- // Return last error
- static OSErr Error() { return error; }
-
- // Change current directory
- static OSErr ChDir(const TFileSpec & spec);
-
- // Set to current directory
- OSErr Default();
-
- TFileSpec() {}
-
- // Construct from FSSpec
- TFileSpec(const FSSpec & spec, Boolean useAlias = false);
-
- // Construct from components
- TFileSpec(short vRefNum, long parID, ConstStr31Param name, Boolean useAlias = false);
-
- // Construct from working directory & file name
- TFileSpec(short wd, ConstStr31Param name, Boolean useAlias = false);
-
- // Construct from full or relative path
- TFileSpec(const char * path, Boolean useAlias = false);
-
- // Give full pathname
- char * FullPath() const;
-
- // Give path relative to current directory
- char * RelPath() const;
-
- // Give information about the current object. If dirInfo is true, give information
- // about the current object's directory.
- OSErr CatInfo(CInfoPBRec & info, Boolean dirInfo = false) const;
-
- // If object is an alias file, resolve it. If gently is true, nonexisting files
- // are tolerated.
- OSErr Resolve(Boolean gently = true);
-
- // Resolve an existing object for which we already have a CInfoPBRec
- OSErr Resolve(const CInfoPBRec & info);
-
- // true if object exists
- Boolean Exists() const;
-
- // true if object is a parent directory of other
- Boolean IsParentOf(const TFileSpec & other) const;
-
- // Replace object with its parent directory
- TFileSpec operator--();
-
- // Equivalent to calling -- levels times
- TFileSpec operator-=(int levels);
-
- // Equivalent to calling -= on a *copy* of the current object
- TFileSpec operator-(int levels) const;
-
- // Replace directory object by object with given name inside the directory
- TFileSpec operator+=(ConstStr31Param name);
- TFileSpec operator+=(const char * name);
-
- // Non-destructive version of +=
- TFileSpec operator+(ConstStr31Param name) const;
- TFileSpec operator+(const char * name) const;
-
- // Return the index-th object in the *parent* directory of the current object
- TFileSpec operator[](short index) const;
-
- // Return if the two filespecs (not) are equal
- Boolean operator==(const TFileSpec & other) const;
- Boolean operator!=(const TFileSpec & other) const;
- };
-
- inline Boolean IsFile(const CInfoPBRec & info)
- {
- return !(info.dirInfo.ioFlAttrib & 0x10);
- }
-
- inline Boolean IsAlias(const CInfoPBRec & info)
- {
- return
- !(info.hFileInfo.ioFlAttrib & 0x10) &&
- (info.hFileInfo.ioFlFndrInfo.fdFlags & (1 << 15));
- }
-
- inline Boolean DirIsExported(const CInfoPBRec & info)
- {
- return (info.hFileInfo.ioFlAttrib & 0x20);
- }
-
- inline Boolean DirIsMounted(const CInfoPBRec & info)
- {
- return (info.hFileInfo.ioFlAttrib & 0x08);
- }
-
- inline Boolean DirIsShared(const CInfoPBRec & info)
- {
- return (info.hFileInfo.ioFlAttrib & 0x04);
- }
-
- inline Boolean HasRdPerm(const CInfoPBRec & info)
- {
- #ifdef OnceThisFieldIsDefined
- return !(info.dirInfo.ioACUser & 0x02);
- #else
- return !(info.dirInfo.filler2 & 0x02);
- #endif
- }
-
- inline Boolean HasWrPerm(const CInfoPBRec & info)
- {
- #ifdef OnceThisFieldIsDefined
- return !(info.dirInfo.ioACUser & 0x04);
- #else
- return !(info.dirInfo.filler2 & 0x04);
- #endif
- }
-
- extern "C" {
- #endif
-
- /* Routines shared between C and C++ */
-
- /* Convert a working directory & file name into a FSSpec. */
- OSErr WD2FSSpec(short wd, ConstStr31Param name, FSSpec * desc);
-
- /* Convert a FSSpec into a full pathname. */
- char * FSp2FullPath(const FSSpec * desc);
-
- /* Works like FSp2FullPath, but creates a *relative* pathname if the object
- is contained in the current directory.
- */
- char * FSp2RelPath(const FSSpec * desc);
-
- /* Call GetCatInfo for file system object. */
- OSErr FSpCatInfo(const FSSpec * desc, CInfoPBRec * info);
-
- /* Return FSSpec of (vRefNum, parID) */
- OSErr FSpUp(FSSpec * desc);
-
- /* Return FSSpec of file in directory denoted by desc */
- OSErr FSpDown(FSSpec * desc, ConstStr31Param name);
-
- /* Return FSSpec of nth file in directory denoted by (vRefNum, parID) */
- OSErr FSpIndex(FSSpec * desc, short n);
-
- /* Convert a pathname into a file spec. */
- OSErr Path2FSSpec(const char * path, FSSpec * desc);
-
- #ifdef __cplusplus
- }
- #endif
- #endif
-